package main;
import javax.swing.ImageIcon;

//The Occupant class holds creatures/players and is a intermediate step
//between specific creatures/players and the Grid.

public class Occupant {

	/**
	 * @param args
	 */
	public int x; //x position on grid
	public int y; //y position on grid
	public String name;
	Cell host = null; //the cell in which the Occpuant resides
	String occImage = ""; //the image to represent the Occupant
	public Occupant(int newX, int newY, String n) //Constructor with initial positions
	{
		int x = newX;
		int y = newY;
		name=n;
	}

	public Occupant(int newX, int newY, String img, String n) //Constructor with initial positions and image
	{
		int x = newX;
		int y = newY;
		occImage=img;
		name=n;
	}

	public Occupant() { //Default constructor
		// TODO Auto-generated constructor stub
	}


	public void changeOccImage(String i){ //changes the image
		occImage = i;
	}
	public void setHost(int newX, int newY, Cell cell1) //change the host cell
	{
		host = cell1;
		x = newX;
		y = newY;
	}
	public void moveLeft() //moves Left
	{
		if (x > 0 && !host.getGrid().cellGrid[x-1][y].hasOccupant())
		{
			host.getGrid().cellGrid[x][y].removeOccupant();
			x = x - 1;
			host.getGrid().putOccupant(x,y,this);
		}
		else
		{
			//System.out.println("At left border of grid."); //returns if at border
		}
	}
	public void moveRight() //moves Right
	{
		if (x < host.getGrid().width() - 1&& !host.getGrid().cellGrid[x+1][y].hasOccupant())
		{
			host.getGrid().cellGrid[x][y].removeOccupant();
			x = x + 1;
			host.getGrid().putOccupant(x,y,this);
		}
		else
		{
			//System.out.println("At right border of grid."); //returns if at border
		}
	}
	public void moveUp() //moves Up
	{
		if (y < host.getGrid().length() - 1 && !host.getGrid().cellGrid[x][y+1].hasOccupant())
		{
			host.getGrid().cellGrid[x][y].removeOccupant();
			y = y + 1;
			host.getGrid().putOccupant(x,y,this);
		}
		else
		{
			//System.out.println("At upper border of grid."); //returns if at border
		}
	}
	public void moveDown() //moves Down
	{
		if (y > 0 && !host.getGrid().cellGrid[x][y-1].hasOccupant())
		{
			host.getGrid().cellGrid[x][y].removeOccupant();
			y = y - 1;
			host.getGrid().putOccupant(x,y,this);
		}
		else
		{
		//	System.out.println("At bottom border of grid."); //returns if at border
		}
	}

	public String getImage(){ //returns the image of the Occupant
		return occImage;
	}

	public void printCoords() //prints the co-ordinates of the Occupant
	{
		System.out.println("column:"+x);
		System.out.println("row:"+y);
	}

	public void removeFromGrid(){ //removes the occupant
		host.removeOccupant();
	}

}